package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import model.TrainCourse;

import util.DBUtil;
import vo.GetEmpTrainDetail;
import dao.GetEmpTrainDetailDAO;

public class GetEmpTrainDetailDAOImpl implements GetEmpTrainDetailDAO {

	public List<GetEmpTrainDetail> getByEmpIdAndTrainId(int empid, int trainid) {
		DBUtil dbu = new DBUtil();
		Connection conn = null;
		PreparedStatement pstat = null;
		ResultSet rs = null;
		TrainCourse tc=null;
		List<GetEmpTrainDetail> list=new ArrayList<GetEmpTrainDetail>();
		try {
			conn = dbu.getConnection();
			String sql = "select * from getemptraindetail where empid=? and trainid=?";
			pstat = conn.prepareStatement(sql);
			pstat.setInt(1, empid);
			pstat.setInt(2, trainid);
			rs=pstat.executeQuery();
			while(rs.next())
			{
				GetEmpTrainDetail getd=new GetEmpTrainDetail();
				getd.setEmpid(rs.getInt("empid"));
				getd.setEmpname(rs.getString("empname"));
				getd.setEmpno(rs.getString("empno"));
				getd.setTrainid(rs.getInt("trainid"));
				getd.setTrainname(rs.getString("trainname"));
				getd.setCourseid(rs.getInt("courseid"));
				getd.setCoursetime(rs.getDouble("coursetime"));
				getd.setCoursename(rs.getString("name"));
				getd.setPercent(rs.getDouble("percent"));
				getd.setScore(rs.getDouble("score"));
				getd.setSummark(rs.getDouble("mark"));
				getd.setTraincourseid(rs.getInt("traincourseid"));
				list.add(getd);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			dbu.closeConnection(conn, pstat, rs);
		}
		return list;
	}

}
